<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /**
     * @param {number[]} digits
     * @return {number[]}
     */
    var plusOne = function(digits) {
      let arr = [...digits];
      for (let i = arr.length - 1; i >= 0; i--) {
        let num = arr[i] + 1;
        if (num < 10) {
          arr[i] = num;
          return arr;
        } else {
          arr[i] = num % 10; // 只留下余数
        }
      }
      // 解决头部为0的自动进位
      arr[0] %= 10
      arr.unshift(1)
      return arr;
    };
    console.log(plusOne([9,9]));
  </script>
</html>
